<?php

	//generate the query and escape it
	$query = "SELECT * FROM CS275.professor";
	
	//connect to database
	$link = mysql_connect('localhost', 'root', 'admin');
	if(!$link){
		die('Could not connect: ' . mysql_error());	
	}
	
	//perform query
	$result = mysql_query($query, $link);
	
	$stack = array();
	//if we get results
	while($row = mysql_fetch_assoc($result)){
		array_push($stack, array("id" => $row["id"], "professor" => $row["professor"]));
	}
	
	//free results
	mysql_free_result($result);
	
	//close link
	mysql_close($link);
	
	//output json
	echo(json_encode(array("professors" => $stack)));
?>